#![allow(dead_code)]
use sqlx::mysql::MySqlRow;
use sqlx::{FromRow, Row};
use sqlx::Error;

pub struct CountNum{
	pub count_num: i64,
}

impl<'c> FromRow<'c, MySqlRow> for CountNum {
	fn from_row(row: &MySqlRow) -> Result<CountNum, Error> {
		Ok(CountNum{
			count_num:row.get(0),
		})
	}
}

pub fn get_image_base64(data:Option<Vec<u8>>)->String{
	match data {
		Some(data) => {
			base64::encode(data)
		},
		None => "".to_string()
	}
}

pub fn get_i64(data:Option<i64>)->i64{
	match data {
		Some(data) => data,
		None => 0
	}
}

pub fn get_i32(data:Option<i32>)->i32{
	match data {
		Some(data) => data,
		None => 0
	}
}


pub fn get_f64(data:Option<f64>)->f64{
	match data {
		Some(data) => data,
		None => 0.0
	}
}

pub fn get_f32(data:Option<f32>)->f32{
	match data {
		Some(data) => data,
		None => 0.0
	}
}

pub fn get_string(data:Option<String>)->String{
	match data {
		Some(data) => data,
		None => "".to_string()
	}
}

pub fn get_bool(data:Option<bool>)->bool{
	match data {
		Some(data) => data,
		None => false
	}
}

pub fn get_dropdown(data:Option<i64>)->i64{
	match data {
		Some(data) => {
			if data <= 0 { return -1;}
			else { return data;}
		},
		None => -1
	}
}
